from django.shortcuts import render
from django.contrib import messages
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from root.utils import request_all_pages, clear_page_cache

@login_required()
def RefreshPageCache(r):
    try:
        clear_page_cache()
        request_all_pages()
        messages.success(r, 'Page Cache has been refreshed!')

    except Exception as e:
        messages.error(r, e )
    return redirect('/admin/')